<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>后台管理系统</title>
    <meta name="renderer" content="bew">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/static/bews/css/login.css">
    <script type="text/javascript" src="/static/layui/layui.js"></script>
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <img src="/static/bews/images/logo.jpg"/>
            <h2>后台管理系统</h2>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <form class="layui-form login-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="username"></label>
                    <input type="text" id="username" name="username" placeholder="用户名" class="layui-input" value="">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="password"></label>
                    <input type="password" id="password" name="password" placeholder="密码" class="layui-input" value="">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="code"></label>
                            <input type="text" id="code" name="code" placeholder="图形验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left:10px;">
                                <img id="img_code" src="{:captcha_src()}" class="layadmin-user-login-codeimg" onclick="reloadCode()">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom: 20px;">
                    <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                </div>
            </form>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" onclick="login()">登 陆</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form'],function(){
        form = layui.form;
        layer = layui.layer;
        $ = layui.jquery;
        // 用户名控件获取焦点
        $('#username').focus();
    });

    //重新加载验证码
    function reloadCode(){
        $('#img_code').attr('src',"{:captcha_src()}?rand="+Math.random());
    }

    //登录
    function login(){
        $.post('/login/login',$('form').serialize(),function(res){
            if(res.code == 0){
                //layer提示登录成功 icon 1
                layer.msg(res.message,{'icon':1});
                //1s后跳转
                setTimeout(function(){
                    location.href = '/index/index';
                },1000);
            }else{
                layer.msg(res.message,{'icon':2});
                reloadCode();
            }
        },'json');
    }

</script>